package bb.lanxing.util;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

/**
 * 输入法管理
 */
public class IMEUtil {
    /**
     * 关闭输入法
     *
     * @param context
     */
    public static void hideInputMethod(Context context) {
        if (context instanceof Activity activity) {
            View a = activity.getCurrentFocus();
            if (a != null) {
                InputMethodManager imm = (InputMethodManager) context.getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                try {
                    imm.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}